<script type="text/javascript">
	var $pagesadd_content = $("#pagesadd_content");

	$(document).ready(function () {
		var theme = 'fresh';

		var pagesadd_save = $("#pagesadd_save");
		var pagesadd_cancel = $("#pagesadd_cancel");
		var pagespost_id = $("#pagespost_id");
		var pagespost_task = $("#pagespost_task");
		var pagespost_judul = $("#pagespost_judul");
		var pagespost_gambar = $("#pagespost_gambar");
		var pagespost_gambarname = $("#pagespost_gambarname");
		var pagespost_tag = $("#pagespost_tag");
		var pagespost_isi = $("#pagespost_isi");
		var pagespost_publish = $("#pagespost_publish");

		$('.field_input').addClass('jqx-input');
		$('.field_input').addClass('field');
		$('.field_input').addClass('jqx-rc-all');

		pagesadd_save.jqxButton({ theme : theme, width : '70px', height : '18px' });
		pagesadd_cancel.jqxButton({ width : '70px' , height : '18px' ,theme : theme });

		pagespost_gambar.fileupload({
			dataType: 'json',
			formData : function(form){
				return [{ name: 'kode', value: 'asdasd' }];
			},
			done: function (e, data){
				var text = "";
				$.each(data.result, function (index, file) {
					text = text + file.name;
					pagespost_gambarname.val(text);
				});
			}
		});
		pagespost_isi.wysibb();

		pagesadd_cancel.click(function(){
			$('#mainpanelcontent').empty();
			$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
			$('#mainpanelcontent').load('index.php/c_pages/pages_load');
		});
		pagesadd_save.click(function(){
			var id = "";
			var judul = "";
			var gambar = "";
			var tag = "";
			var publish ="";
			var isi = "";
			var task = "";

			id = pagespost_id.val();
			judul = pagespost_judul.val();
			gambar = pagespost_gambarname.val();
			tag = pagespost_tag.val();
			isi = pagespost_isi.htmlcode();
			if (pagespost_publish.prop("checked")==true) {
				publish = 'y';
			}else{
				publish = 't';
			}

			task = pagespost_task.val();

			if(task == ""){
				task = "create";
			}
			$.ajax({
				type : 'POST',
				url : 'index.php/c_pages/pages_save',
				data : {
					id : id,
					judul : judul,
					gambar : gambar,
					tag : tag,
					isi : isi,
					publish : publish,
					task : task
				},success : function(msg){
					var result = eval(msg);
					switch(result){
						case 1:
							$('#mainpanelcontent').empty();
							$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
							$('#mainpanelcontent').load('index.php/c_pages/pages_load');
							alert("Data berhasil disimpan");
							break;
						default:
							alert("Data gagal disimpan");
							break;
					}
				}
			});
		});

		<?php
			if(isset($dataDetail)){
		?>
			pagespost_id.val('<?php echo $dataDetail->id; ?>');
			pagespost_judul.val('<?php echo $dataDetail->judul; ?>');
			pagespost_tag.val('<?php echo $dataDetail->tag; ?>');
			pagespost_isi.htmlcode(<?php echo json_encode($dataDetail->isi); ?>);

			pagespost_gambarname.val('<?php echo $dataDetail->image_page; ?>');
			pagespost_task.val('update');
		<?php
				if($dataDetail->publish=='y'){
					echo "pagespost_publish.prop(\"checked\", true);";
				}
			}
		?>

	});

</script>
<!-- Begin content -->
<div class="modal_header">
		<span>Pages Form</span>
	</div>
<div class="modal_content">
<div id="pagesadd_content">
	<input type="hidden" id="pagespost_id">
	<input type="hidden" id="pagespost_task">
	<form action="" method="post" >
		<p>
			<label>Judul:</label><br/>
			<input type="text" id="pagespost_judul" class="field_input" style="width:300px"/>
		</p>
		<br/>
		<p>
			<label>Gambar:</label><br/>
			<input type="file" id="pagespost_gambar" name="userfile" style="width:300px" data-url="index.php/upload/upload_img" />
			<input type="hidden" id="pagespost_gambarname">
		</p>
		<br/>
		<p>
			<label>Tag:</label><br/>
			<input type="text" id="pagespost_tag" class="field_input" style="width:300px"/>
		</p>
		<br/>
		<p>
			<label>Isi:</label><br/>
			<textarea rows="10" cols="50" id="pagespost_isi" class="wysiwyg" ></textarea>
		</p>
		<p>
			<input type="checkbox" class="checkbox"  id="pagespost_publish" > <label for="cbdemo1">Publish</label>
		</p>
		<br/><br/>

		<p>
			<table align="left">
				<tr align="left">
					<td>
						<div id='pagesadd_save'>
						<img style='float: left; margin: 0px;' src='./images/icons/save.gif' />
						<div style='float: left; margin-left: 4px;'>Simpan</div>
					</div>
					</td>
					<td>
						<div id='pagesadd_cancel'>
						<img style='float: left; margin: 0px;' src='./images/icons/cross.gif' />
						<div style='float: left; margin-left: 4px;'>Cancel</div>
					</div>
					</td>
				</tr>
			</table>
		</p>
		<p>&nbsp;<br/></p>
	</form>
</div>
</div>
<!-- End left column window -->
